package com.gali.juc;

import java.util.concurrent.TimeUnit;

/**
 * @Auther: gali
 * @Date: 2022-08-19 18:19
 * @Description:
 */
public class InterruptDemo {
    public static void main(String[] args) {
        Thread a = new Thread(() -> {
            for (int i = 0; i < 300; i++) {
                System.out.println("-----"+i);
            }
            System.out.println("a线程的调用interrupt方法中断标志2"+Thread.currentThread().isInterrupted());

        }, "a");
        a.start();

        System.out.println("a线程的默认中断标志"+a.isInterrupted());

        try {
            TimeUnit.MILLISECONDS.sleep(2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        a.interrupt();
        System.out.println("a线程的调用interrupt方法中断标志"+a.isInterrupted());


        try {
            TimeUnit.SECONDS.sleep(2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println("a线程的调用interrupt方法中断标志3"+a.isInterrupted());//false

    }
}
